<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<script src="./js/velocity.min.js"></script>
<script src="./js/lodash.min.js"></script>
<script src="../vue.js"></script>

<body>
  <div id="app">
    <!-- // 双向数据绑定 -->
    <input type="text" placeholder="请输入要查找的内容：" v-model="query">
    <transition-group name="item" tag="ul" @before-enter="beforeEnter" @enter="enter" @leave="leave" :css="false">
      <!-- //:css="false" 只用钩子函数定义好的样式，不用外部样式 -->
      <li v-for="(item, index) in ComputedList" :key="item.msg" :data-index="index">
        {{item.msg}}
      </li>
    </transition-group>
  </div>


  <script>
    var vm = new Vue({
      el: "#app",
      data: {
        query: "", // v-model绑定的值
        items: [{
            msg: '张三'
          }, {
            msg: '李四'
          }, {
            msg: '张芳芳'
          },
          {
            msg: '王琳琳'
          }, {
            msg: '冯圆'
          }
        ]
      },
      computed: {
        ComputedList() {
          var vm = this.query;
          var nameList = this.items;
          nameList.filter(function (item) {
            return
            item.msg.toLowerCase().indexOf(vm.toLowerCase()) !== -1; // tolowerCase（）字符串转换为小写 // 不等于-1就表示包含
          })
        }
      },
      methods: {
        beforeEnter(el) {
          el.style.opacity = 0;
          el.style.height = 0
        },
        enter(el, done) {
          var delay = el.dataset.index * 150;
          setTimeout(function () {
            Velocity(el, { // Velocity调用钩子函数 第一个参数是挂载对象，第二个是参数是要设置的样式属性
              opacity: 1,
              height: "1.6em"
            }, {
              complete: done,
            })
          }, 1500)
        },
        leave(el, done) {
          var delay = el.dataset.index * 150;
          setTimeout(function () {
            Velocity(el, {
              opacity: 0,
              height: 0
            }, {
              complete: done,
            })
          }, 1500)
        },
      }
    })
  </script>
</body>

</html>